package gui;


import javax.swing.*;

import code.Settings;

import java.awt.*;
import java.io.*;
import java.awt.image.*;

/**
 * Background image demo
 */

public class ViewCertificate extends JPanel {

	Color c= new Color(219, 191, 144);

	Image bgImage=null;
	private Settings s;
	
	JLabel jLabel = new JLabel("First Name :");
	JLabel jLabel1 = new JLabel("Last Name :");
	JLabel jLabel2 = new JLabel("Organizational Unit :");
	JLabel jLabel3 = new JLabel("Organization :");
	JLabel jLabel4 = new JLabel("City :");
	JLabel jLabel5 = new JLabel("State or Provience :");
	JLabel jLabel6 = new JLabel("Country :");
	JLabel jLabel7 = new JLabel("Alias :");
	JLabel jLabel8 = new JLabel("Key Size :");
	JLabel jLabel9 = new JLabel("Not Before (Date) :");
	JLabel jLabel10 = new JLabel("Not After (Date) :");
	JLabel jLabel11 = new JLabel("Back");

	JTextField jTextField = new JTextField();
	JTextField jTextField1 = new JTextField();
	JTextField jTextField2 = new JTextField();
	JTextField jTextField3 = new JTextField();
	JTextField jTextField4 = new JTextField();
	JTextField jTextField5 = new JTextField();
	JTextField jTextField6 = new JTextField();
	JTextField jTextField7 = new JTextField();
	JTextField jTextField8 = new JTextField();
	JTextField jTextField9 = new JTextField();
	JTextField jTextField10 = new JTextField();

	JTextField field = new JTextField(20);
	String message="";
	public ViewCertificate() {
		super(null);
		try {
			getFileImage((String) s.global.get("installPath") + File.separator + "images/en/parchment.jpg");
			jLabel.setBounds(new Rectangle(90, 75, 107, 16));
			jLabel1.setBounds(new Rectangle(90, 105, 107, 16));
			jLabel2.setBounds(new Rectangle(90, 135, 119, 16));
			jLabel3.setBounds(new Rectangle(90, 165, 107, 16));
			jLabel4.setBounds(new Rectangle(90, 195, 107, 16));
			jLabel5.setBounds(new Rectangle(90, 225, 113, 16));
			jLabel6.setBounds(new Rectangle(90, 255, 107, 16));
			jLabel7.setBounds(new Rectangle(90, 285, 107, 16));
			jLabel8.setBounds(new Rectangle(90, 315, 107, 16));
			jLabel9.setBounds(new Rectangle(90, 345, 109, 16));
			jLabel10.setBounds(new Rectangle(90, 375, 107, 16));
			jLabel11.setBounds(new Rectangle(90, 405, 173, 37));
			jLabel11.setFont(new java.awt.Font("Dialog", Font.BOLD, 15));

			jTextField.setBounds(new Rectangle(210, 75, 115, 20));
			jTextField1.setBounds(new Rectangle(210, 105, 115, 20));
			jTextField2.setBounds(new Rectangle(210, 135, 115, 20));
			jTextField3.setBounds(new Rectangle(210, 165, 115, 20));
			jTextField4.setBounds(new Rectangle(210, 195, 115, 20));
			jTextField5.setBounds(new Rectangle(210, 225, 115, 20));
			jTextField6.setBounds(new Rectangle(210, 255, 115, 20));
			jTextField7.setBounds(new Rectangle(210, 285, 115, 20));
			jTextField8.setBounds(new Rectangle(210, 315, 115, 20));
			jTextField9.setBounds(new Rectangle(210, 345, 115, 20));
			jTextField10.setBounds(new Rectangle(210, 375, 115, 20));
			
			jTextField.setOpaque(false);
			jTextField1.setOpaque(false);
			jTextField2.setOpaque(false);
			jTextField3.setOpaque(false);
			jTextField4.setOpaque(false);
			jTextField5.setOpaque(false);
			jTextField6.setOpaque(false);
			jTextField7.setOpaque(false);
			jTextField8.setOpaque(false);
			jTextField9.setOpaque(false);
			jTextField10.setOpaque(false);

			
			jTextField.setBorder(BorderFactory.createMatteBorder(0, 0, 5, 0, c));
			jTextField1.setBorder(BorderFactory.createMatteBorder(0, 0, 5, 0, c));
			jTextField2.setBorder(BorderFactory.createMatteBorder(0, 0, 5, 0, c));
			jTextField3.setBorder(BorderFactory.createMatteBorder(0, 0, 5, 0, c));
			jTextField4.setBorder(BorderFactory.createMatteBorder(0, 0, 5, 0, c));
			jTextField5.setBorder(BorderFactory.createMatteBorder(0, 0, 5, 0, c));
			jTextField6.setBorder(BorderFactory.createMatteBorder(0, 0, 5, 0, c));
			jTextField7.setBorder(BorderFactory.createMatteBorder(0, 0, 5, 0, c));
			jTextField8.setBorder(BorderFactory.createMatteBorder(0, 0, 5, 0, c));
			jTextField9.setBorder(BorderFactory.createMatteBorder(0, 0, 5, 0, c));
			jTextField10.setBorder(BorderFactory.createMatteBorder(0, 0, 5, 0, c));

			add(jLabel);
			add(jLabel1);
			add(jLabel2);
			add(jLabel3);
			add(jLabel4);
			add(jLabel5);
			add(jLabel6);
			add(jLabel7);
			add(jLabel8);
			add(jLabel9);
			add(jLabel10);
			add(jLabel11);
			add(jTextField);
			add(jTextField1);
			add(jTextField2);
			add(jTextField3);
			add(jTextField4);
			add(jTextField5);
			add(jTextField6);
			add(jTextField7);
			add(jTextField8);
			add(jTextField9);
			add(jTextField10);
		}
		catch (Exception ex) {
			message="File load failed: "+ex.getMessage();
		}
	}
	public void paintComponent(Graphics g) {
		if (bgImage!=null) {
			g.drawImage(bgImage,0,0,this);
		} else {
			g.drawString(message,40,40);
		}
	}
	private void getFileImage(String filePath) throws InterruptedException, IOException {
		FileInputStream in = new FileInputStream(filePath);
		byte [] b=new byte[in.available()];
		in.read(b);
		in.close();
		bgImage=Toolkit.getDefaultToolkit().createImage(b);
		MediaTracker mt=new MediaTracker(this);
		mt.addImage(bgImage,0);
		mt.waitForAll();
	}
	public static void main(String[] args) {
		ViewCertificate bgd=new ViewCertificate();
		JFrame f=new JFrame("Background image");
		f.setBounds(10,10,415,545);
		f.getContentPane().setLayout(new GridLayout());
		f.getContentPane().add(bgd);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setVisible(true);
	}
}
